#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
struct node{
    int d, v, a;
};
int main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    cin >> t;
    while(t--){
        int n, m, l, v;
        cin >> n >> m >> l >> v;
        node a[MAXN] = {{0, 0, 0}};
        int b[MAXN];
        for(int i = 0;i < n;i++){
            cin >> a[i].d >> a[i].v >> a[i].a;
        }
        int mx = 0;
        for(int i = 0;i < m;i++){
            cin >> b[i];
            mx = max(mx, b[i]);
        }
        int ans = 0;
        for(int i = 0;i < n;i++){
            if(a[i].v > v && a[i].d <= mx) ans++;
        }
        cout << ans << ' ' << m - 1 << endl;
    }
    return 0;
}
